home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc1 / alcun101.lha / src / checkrom.c next >
C/C++ Source or Header  |  1995-01-12  |  3KB  |  145 lines

  1. /*
  2.  *  This file is part of x48, an emulator of the HP-48sx Calculator.
  3.  *  Copyright (C) 1994  Eddie C. Dost  (ecd@dressler.de)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. /* $Log: checkrom.c,v $
  21.  * Revision 1.4  1995/01/11  18:20:01  ecd
  22.  * major update to support HP48 G/GX
  23.  *
  24.  * Revision 1.3  1994/11/02  14:40:38  ecd
  25.  * support for "compressed" rom files added
  26.  *
  27.  * Revision 1.3  1994/11/02  14:40:38  ecd
  28.  * support for "compressed" rom files added
  29.  *
  30.  * Revision 1.2  1994/10/06  16:30:05  ecd
  31.  * changed char to unsigned
  32.  *
  33.  * Revision 1.1  1994/10/01  10:12:53  ecd
  34.  * Initial revision
  35.  *
  36.  *
  37.  * $Id: checkrom.c,v 1.4 1995/01/11 18:20:01 ecd Exp ecd $
  38.  */
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <unistd.h>
  43. #include <sys/stat.h>
  44.  
  45. #include "global.h"
  46. #include "romio.h"
  47.  
  48. unsigned char *rom;
  49. unsigned short rom_crc, crc;
  50.  
  51. int   verbose = 0;
  52. char *progname;
  53.  
  54. #define calc_crc(n) (crc = ((crc >> 4) ^ (((crc ^ n) & 0xf) * 0x1081)))
  55.  
  56. int
  57. #ifdef __FunctionProto__
  58. main(int argc, char **argv)
  59. #else
  60. main(argc, argv)
  61. int argc;
  62. char **argv;
  63. #endif
  64. {
  65.   unsigned char version[7];
  66.   long ver_addr;
  67.   int i, a, c, d, d0, d1, D0, D1;
  68.   int fail;
  69.  
  70.   if (argc < 2) {
  71.     fprintf(stderr, "usage: %s rom-file\n", argv[0]);
  72.     exit (1);
  73.   }
  74.  
  75.   if (!read_rom_file(argv[1], &rom, &rom_size))
  76.     {
  77.       fprintf(stderr, "%s: can\'t read ROM from %s\n", argv[0], argv[1]);
  78.       exit (1);
  79.     }
  80.  
  81.   if (opt_gx != 0)
  82.     ver_addr = 0x7ffbf;
  83.   else
  84.     ver_addr = 0x7fff0;
  85.  
  86.   for (i = 0; i < 6; i++) {
  87.     version[i] = rom[ver_addr + 2 * i + 1] << 4;
  88.     version[i] |= rom[ver_addr + 2 * i];
  89.   }
  90.   version[6] = '\0';
  91.   printf("ROM Version is %s\n", version);
  92.  
  93.  
  94.   for (i = 0x100; i < 0x140; i++) {
  95.     rom[i] = 0x0;
  96.   }
  97.  
  98.   fail = a = 0;
  99.   D0 = 0x00000;
  100.   D1 = 0x40000;
  101.   for (d = 1; d <= rom_size / 0x80000; d++) {
  102.  
  103.     crc = 0x0000;
  104.     rom_crc = 0;
  105.     for (i = 0; i < 4; i++) {
  106.       rom_crc <<= 4;
  107.       rom_crc |= (rom[0x80000 * d - i - 1] & 0x0f);
  108.     }
  109.  
  110.     if (opt_gx)
  111.       printf("ROM CRC %d reads 0x%.4x\n", d, rom_crc);
  112.     else
  113.       printf("ROM CRC reads 0x%.4x\n", rom_crc);
  114.  
  115.     d0 = D0;
  116.     d1 = D1;
  117.     for (c = 0x3fff; c >= 0x0000; c--) {
  118.       for (i = 0; i < 16; i++) {
  119.         calc_crc(rom[d0 + i]);
  120.       }
  121.       d0 += 16;
  122.       for (i = 0; i < 16; i++) {
  123.         calc_crc(rom[d1 + i]);
  124.       }
  125.       d1 += 16;
  126.     }
  127.     D0 += 0x80000;
  128.     D1 += 0x80000;
  129.     a = crc;
  130.     a = ((a | 0xf0000) + 1) & 0xfffff;
  131.  
  132.     if (a != 0x00000) {
  133.       fail++;
  134.     }
  135.   }
  136.  
  137.   if (fail != 0)
  138.     printf("IROM %.4x: ROM CRC test FAILED !!!\n", a & 0xffff);
  139.   else
  140.     printf("IROM OK: ROM CRC test passed.\n");
  141.  
  142.   return 0;
  143. }
  144.  
  145.